ContextCompat

open class ContextCompat(source)

Helper for accessing features in Context.

Inheritors

Types

Properties

Link copied to clipboard
Flag for registerReceiver: The receiver can receive broadcasts from other Apps.
Link copied to clipboard
Flag for registerReceiver: The receiver cannot receive broadcasts from other Apps.
Link copied to clipboard
Flag for registerReceiver: The receiver can receive broadcasts from Instant Apps.

Functions

Link copied to clipboard
open fun checkSelfPermission(@NonNull context: @NonNull Context, @NonNull permission: @NonNull String): Int
Determine whether you have been granted a particular permission.
Link copied to clipboard
@NonNull
open fun createAttributionContext(@NonNull context: @NonNull Context, @Nullable attributionTag: @Nullable String): @NonNull Context
Return a new Context object for the current Context but attribute to a different tag.
Link copied to clipboard
@Nullable
open fun createDeviceProtectedStorageContext(@NonNull context: @NonNull Context): @Nullable Context
Return a new Context object for the current Context but whose storage APIs are backed by device-protected storage.
Link copied to clipboard
@Nullable
open fun getAttributionTag(@NonNull context: @NonNull Context): @Nullable String
Attribution can be used in complex apps to logically separate parts of the app.
Link copied to clipboard
@NonNull
open fun getCodeCacheDir(@NonNull context: @NonNull Context): @NonNull File
Returns the absolute path to the application specific cache directory on the filesystem designed for storing cached code.
Link copied to clipboard
open fun getColor(@NonNull context: @NonNull Context, @ColorRes id: Int): Int
Returns a color associated with a particular resource ID Starting in M, the returned color will be styled for the specified Context's theme.
Link copied to clipboard
@Nullable
open fun getColorStateList(@NonNull context: @NonNull Context, @ColorRes id: Int): @Nullable ColorStateList
Returns a color state list associated with a particular resource ID.
Link copied to clipboard
@NonNull
open fun getContextForLanguage(@NonNull context: @NonNull Context): @NonNull Context
Gets the context which respects the per-app locales locale.
Link copied to clipboard
@Nullable
open fun getDataDir(@NonNull context: @NonNull Context): @Nullable File
Returns the absolute path to the directory on the filesystem where all private files belonging to this app are stored.
Link copied to clipboard
@NonNull
open fun getDisplayOrDefault(@NonNull context: @NonNull Context): @NonNull Display
Get the display this context is associated with or the default display as the fallback if the context is not associated with any Display.
Link copied to clipboard
@Nullable
open fun getDrawable(@NonNull context: @NonNull Context, @DrawableRes id: Int): @Nullable Drawable
Returns a drawable object associated with a particular resource ID.
Link copied to clipboard
open fun getExternalCacheDirs(@NonNull context: @NonNull Context): @NonNull Array<File>
Returns absolute paths to application-specific directories on all external storage devices where the application can place cache files it owns.
Link copied to clipboard
open fun getExternalFilesDirs(@NonNull context: @NonNull Context, @Nullable type: @Nullable String): @NonNull Array<File>
Returns absolute paths to application-specific directories on all external storage devices where the application can place persistent files it owns.
Link copied to clipboard
@NonNull
open fun getMainExecutor(@NonNull context: @NonNull Context): @NonNull Executor
Return an Executor that will run enqueued tasks on the main thread associated with this context.
Link copied to clipboard
@Nullable
open fun getNoBackupFilesDir(@NonNull context: @NonNull Context): @Nullable File
Returns the absolute path to the directory on the filesystem similar to getFilesDir.
Link copied to clipboard
open fun getObbDirs(@NonNull context: @NonNull Context): @NonNull Array<File>
Returns absolute paths to application-specific directories on all external storage devices where the application's OBB files (if there are any) can be found.
Link copied to clipboard
@NonNull
open fun getString(@NonNull context: @NonNull Context, resId: Int): @NonNull String
Gets the resource string that also respects the per-app locales.
Link copied to clipboard
open fun <T> getSystemService(@NonNull context: @NonNull Context, @NonNull serviceClass: @NonNull Class<T>): @Nullable T
Return the handle to a system-level service by class.
Link copied to clipboard
@Nullable
open fun getSystemServiceName(@NonNull context: @NonNull Context, @NonNull serviceClass: @NonNull Class<out Any>): @Nullable String
Gets the name of the system-level service that is represented by the specified class.
Link copied to clipboard
open fun isDeviceProtectedStorage(@NonNull context: @NonNull Context): Boolean
Indicates if the storage APIs of this Context are backed by device-encrypted storage.
Link copied to clipboard
@Nullable
open fun registerReceiver(@NonNull context: @NonNull Context, @Nullable receiver: @Nullable BroadcastReceiver, @NonNull filter: @NonNull IntentFilter, flags: Int): @Nullable Intent
@Nullable
open fun registerReceiver(@NonNull context: @NonNull Context, @Nullable receiver: @Nullable BroadcastReceiver, @NonNull filter: @NonNull IntentFilter, @Nullable broadcastPermission: @Nullable String, @Nullable scheduler: @Nullable Handler, flags: Int): @Nullable Intent
Register a broadcast receiver.
Link copied to clipboard
open fun startActivities(@NonNull context: @NonNull Context, intents: @NonNull Array<Intent>): Boolean
open fun startActivities(@NonNull context: @NonNull Context, intents: @NonNull Array<Intent>, @Nullable options: @Nullable Bundle): Boolean
Start a set of activities as a synthesized task stack, if able.
Link copied to clipboard
open fun startActivity(@NonNull context: @NonNull Context, @NonNull intent: @NonNull Intent, @Nullable options: @Nullable Bundle)
Start an activity with additional launch information, if able.
Link copied to clipboard
open fun startForegroundService(@NonNull context: @NonNull Context, @NonNull intent: @NonNull Intent)
startForegroundService() was introduced in O, just call startService for before O.